import LoadManager from "../../manager/LoadManager";
import UIManager from "../../manager/UIManager";
import UIConst from "../../const/UIConst";
import LoginModel from "../../model/LoginModel";
import SceneManager from "../../manager/SceneManager";
import UserData from "../../data/UserData";

const {ccclass, property} = cc._decorator;

@ccclass
export default class LoginScene extends cc.Component {
    @property(cc.Label)
    txt_load:cc.Label = null;
    @property(cc.Sprite)
    img_logo:cc.Sprite = null;
    onLoad()
    {
        this.preloadRes()
    }
    private preloadRes() {
        LoadManager.instance.init()
        LoginModel.instance.init()
    }
    start () 
    {
        let action:cc.ActionInterval = cc.sequence(cc.scaleTo(1,0.8,0.8),cc.scaleTo(1,1,1)) 
        action = cc.repeatForever(action)
        this.img_logo.node.runAction(action)
        this.img_logo.node.active = false
    }
    private init:boolean = true
    update()
    {
        let isLoadedComplete:boolean = LoadManager.instance.isLoadedResComplete
        //资源加载完成
        if (isLoadedComplete&&this.init)
        {   
            this.init = false
            this.txt_load.string = "游戏加载已完成"
            let userData:UserData = LoginModel.instance.userData
            if (userData)
            {
                SceneManager.instance.goto("MainScene")
            }
            else
            {
                UIManager.instance.show(UIConst.VIEW_CREATEUSER,true)
            } 
        }
    }
}
